﻿Public Class frmLop

    Private Sub ThêmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThêmToolStripMenuItem.Click
        Dim frm As frmThemLop = New frmThemLop
        frm.ShowDialog()
        Me.Close()
    End Sub

    Private Sub XóaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XóaToolStripMenuItem.Click
        Dim dr As DialogResult

        If dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString() <> "" Then
            dr = MessageBox.Show("Bạn muốn xóa?", "Delete!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)
            If dr = DialogResult.Yes Then
                Dim lop As DAOLop = New DAOLop
                If lop.Delete(dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString(), Application.StartupPath + "\database\database.mdb") Then
                    LoadAllData()
                Else
                    MessageBox.Show("Xóa không thành công.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                    Return
                End If
            End If
        End If
    End Sub

    Private Sub SửaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SửaToolStripMenuItem.Click
        Dim lop As DTOLop = New DTOLop

        If dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString() <> "" Then
            lop.TenLop = dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString()
            lop.SiSo = Convert.ToInt64(dtgDanhSachLop.CurrentRow.Cells("ColSiSo").Value.ToString())
            Dim frm As frmThemLop = New frmThemLop(lop)
            frm.ShowDialog()
            Me.Close()
        Else
            MessageBox.Show("Bạn chưa chọn giá trị.", "Thông báo.", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
            Return
        End If

        
    End Sub

    Private Sub XemDanhSáchLớpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XemDanhSáchLớpToolStripMenuItem.Click
        Try
            If dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString() <> "" Then
                Dim tenlop As String = dtgDanhSachLop.CurrentRow.Cells("ColTenLop").Value.ToString()
                Dim frm As frmDanhSachHocSinh_Lop = New frmDanhSachHocSinh_Lop(tenlop)
                frm.ShowDialog()
            Else
                MessageBox.Show("Bạn chưa chọn giá trị.")
            End If

        Catch ex As Exception
            MessageBox.Show("Lỗi.")
        End Try
       
    End Sub

    Private Sub QuyĐịnhToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuyĐịnhToolStripMenuItem.Click
        Dim frm As frmQuyDinh = New frmQuyDinh
        frm.tctQuyDinh.SelectedIndex = 1
        frm.ShowDialog()
        Me.Close()
    End Sub
    Public Sub LoadAllData()
        Dim lop As DAOLop = New DAOLop
        Dim ds As DataSet = New DataSet
        ds = lop.LoadAllData(Application.StartupPath + "\database\database.mdb")
        dtgDanhSachLop.AutoGenerateColumns = False
        dtgDanhSachLop.DataSource = ds.Tables("Lop")
    End Sub
    Private Sub frmLop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadAllData()
    End Sub
End Class